#include "mytextbrowser.h"
#include "mymenu.h"



MyTextBrowser::MyTextBrowser(QWidget *parent)
    : QWidget{parent}
{
    // 将上下文菜单策略设置为自定义上下文菜单
    setContextMenuPolicy(Qt::CustomContextMenu);


    // 将customContextMenuRequested信号连接到show_menu槽函数上
    connect(this, &MyTextBrowser::customContextMenuRequested, this, &MyTextBrowser::show_menu);

    connect(&menu, &MyMenu::copyClicked, this, &MyTextBrowser::buttonPressed);
}

void MyTextBrowser::show_menu(const QPoint &pos)
{
    if (this->isHidden()) return;

    menu.exec(mapToGlobal(pos)); // 在当前窗口中显示菜单

    return;
}

void MyTextBrowser::buttonPressed()
{
    emit copyed();
}




